import {request} from '@umijs/max';
import * as API from "@/services";
import {Article_Num} from "@/services";


/** 文章 分页检索请求 */
export async function queryArticles(params?: API.ArticlePageQueryParams): Promise<API.RespPageResult<API.Article>> {
  return request('/api/v1/article', {
    params,
  });
}

/** 文章 详情请求 */
export async function queryArticle(bizId: API.EntityId): Promise<API.RespResult<API.Article>> {
  return request(`/api/v1/article/${bizId}`);
}

/** 文章 创建请求 */
export async function createArticle(entity: API.Article_Create): Promise<API.RespResult<any>> {
  return request(`/api/v1/article`, {
    method: 'POST',
    data: entity,
  });
}

/** 文章 修改请求 */
export async function modifyArticle(entity: API.Article_Modify): Promise<API.RespResult<any>> {
  return request(`/api/v1/article/${entity.id}`, {
    method: 'PUT',
    data: entity,
  });
}

export async function modifyArticleSpecialTopicId(entity: API.Article_SpecialTopicIdModify): Promise<API.RespResult<any>> {
  return request(`/api/v1/article/${entity.articleId}/special-topic-id`, {
    method: 'POST',
    data: entity,
  });
}


/** 文章 修改(部分)请求 */
export async function patchArticle(entity: API.Article_Patch): Promise<API.RespResult<any>> {
  return request(`/api/v1/article/${entity.id}`, {
    method: 'PATCH',
    data: entity,
  });
}

/** 文章 删除请求 */
export async function deleteArticle(bizId: API.EntityId): Promise<API.RespResult<any>> {
  return request(`/api/v1/article/${bizId}`, {
    method: 'DELETE',
  });
}

/** 文章 批量删除请求 */
export async function deleteArticles(bizIds: API.EntityId[]): Promise<API.RespResult<any>> {
  return request(`/api/v1/article`, {
    method: 'DELETE',
    data: {
      ids: bizIds,
    },
  });
}

/** 文章 修改下载次数请求 */
export async function patchArticleDownload(entity: API.Article_Num): Promise<API.RespResult<any>> {
  return request(`/api/v1/article/${entity.id}/download`, {
    method: 'PATCH',
    data: entity,
  });
}


/** 文章 修改访问次数请求 */
export async function patchArticleAccess(entity: API.Article_Num): Promise<API.RespResult<any>> {
  return request(`/api/v1/article/${entity.id}/access`, {
    method: 'PATCH',
    data: entity,
  });
}

/**
 * 下载PDF(权限检查)
 */
export async function preCheckArticleDownload(bizId: API.EntityId, opts?: API.AxiosRequestOpts): Promise<API.RespResult<boolean>> {
  return request(`/api/v1/front/article/${bizId}/pdf/pre-check`, {
    method: "POST",
    ...(opts || {}),
  });
}
